package com.rongshe.hotel.service.impl;

import java.util.List;
import com.rongshe.common.utils.DateUtils;
import com.rongshe.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rongshe.hotel.mapper.RsOrderMapper;
import com.rongshe.hotel.domain.RsOrder;
import com.rongshe.hotel.service.IRsOrderService;

/**
 * 订单Service业务层处理
 * 
 * @author rongshe
 * @date 2025-02-17
 */
@Service
public class RsOrderServiceImpl implements IRsOrderService 
{
    @Autowired
    private RsOrderMapper rsOrderMapper;

    /**
     * 查询订单
     * 
     * @param id 订单主键
     * @return 订单
     */
    @Override
    public RsOrder selectRsOrderById(Long id)
    {
        return rsOrderMapper.selectRsOrderById(id);
    }

    /**
     * 查询订单列表
     * 
     * @param rsOrder 订单
     * @return 订单
     */
    @Override
    public List<RsOrder> selectRsOrderList(RsOrder rsOrder)
    {
        return rsOrderMapper.selectRsOrderList(rsOrder);
    }

    /**
     * 新增订单
     * 
     * @param rsOrder 订单
     * @return 结果
     */
    @Override
    public int insertRsOrder(RsOrder rsOrder)
    {
        rsOrder.setCreateTime(DateUtils.getNowDate());
        rsOrder.setUpdateTime(DateUtils.getNowDate());
        return rsOrderMapper.insertRsOrder(rsOrder);
    }

    /**
     * 修改订单
     * 
     * @param rsOrder 订单
     * @return 结果
     */
    @Override
    public int updateRsOrder(RsOrder rsOrder)
    {
        rsOrder.setUpdateTime(DateUtils.getNowDate());
        if(StringUtils.isNotEmpty(rsOrder.getStatus())){
            switch (rsOrder.getStatus()){
                case "1":
                    rsOrder.setOrderTime(DateUtils.getNowDate());
                    break;
                case "2":
                    rsOrder.setCompleteTime(DateUtils.getNowDate());
                    break;
                case "3":
                    rsOrder.setCancelTime(DateUtils.getNowDate());
                    break;
                case "4":
                    rsOrder.setConfirmTime(DateUtils.getNowDate());

            }
        }
        return rsOrderMapper.updateRsOrder(rsOrder);
    }

    /**
     * 批量删除订单
     * 
     * @param ids 需要删除的订单主键
     * @return 结果
     */
    @Override
    public int deleteRsOrderByIds(Long[] ids)
    {
        return rsOrderMapper.deleteRsOrderByIds(ids);
    }

    /**
     * 删除订单信息
     * 
     * @param id 订单主键
     * @return 结果
     */
    @Override
    public int deleteRsOrderById(Long id)
    {
        return rsOrderMapper.deleteRsOrderById(id);
    }
}
